package com.jlb.base.interceptor;

import org.springframework.boot.SpringBootConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * Created by lixin on 2018/6/23.
 */
@SpringBootConfiguration
public class ContextConfiguration extends WebMvcConfigurerAdapter {

    @Bean
    public LoginInterceptor loginInterceptor() {
        return new LoginInterceptor();
    }

    @Bean
    public ContextInterceptor contextInterceptor() {
        return new ContextInterceptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //全局拦截器
        registry.addInterceptor(contextInterceptor())
                .excludePathPatterns("/swagger-resources/**")
                .addPathPatterns("/**");

        //登录拦截器
        registry.addInterceptor(loginInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns("/swagger-resources/**", "/login/**", "/res/**", "/reg/**", "/basicArea/**", "/app/setting/**", "/zxMember/**", "/userMiner/digOut**", "/userMiner/delete**", "/userMiner/jobtoken**", "/news/upload**", "/error");

        super.addInterceptors(registry);
    }
}
